﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business.DwzFrame;
using ZLCMS.Business.Util;
using DotNet.Common.Command;
using ZLCMS.Commands.User.Commands.Order;
using ZLCMS.Data.Model;
using NHibernate;
using System.Collections;

namespace ZLCMS.Web.SystemManage.Basics.Shop.OrderReturns
{
    public partial class OrderRefundProcess : System.Web.UI.Page
    {
        protected FrameHelper _framePage;
        protected string _userAccount;
        string oid;

        protected IDictionary RefundData { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            _userAccount = UserKit.GetUserAccountFailLogin();
            //初始化DWZ控件
            _framePage = new FrameHelper(this);


            if (!IsPostBack)
            {
                oid = Request["rno"] == null ? "" : Request["rno"];
                _oid.Text = oid;
            }
            else
            {
                oid = _oid.Text;
                Save();
            }

            LoadOrderRefundDetailResult result = new LoadOrderRefundDetailCommand().Execute(new LoadOrderRefundDetailParameter()
            {
                RefundNo = Request["rno"],
                UserAccount = UserKit.GetUserAccount()
            }).Result;

            RefundData = result.RefundData;
        }

        protected void Save()
        {

            ICommandResult<ProcessOrderRefundResult> res = new ProcessOrderRefundCommand().Execute(new ProcessOrderRefundParameter()
            {
                RefundNo = _oid.Text,
                UserAccount = _userAccount
            });
            if (res.Error)
            {
                _framePage.Alert(new ReturnCode()
                {
                    statusCode = 300,
                    message = "操作失败!",
                    callbackType = "closeCurrent",
                    navTabId = "OrderRefundDetail"
                });
            }
            else
            {
                _framePage.Alert(new ReturnCode()
                {
                    statusCode = 200,
                    message = "操作成功!",
                    callbackType = "closeCurrent",
                    navTabId = "OrderRefundDetail"
                });
            }

        }
    }
}
